package com.bosssoft.ct.springcloud.pojo.vo;

import com.bosssoft.ct.springcloud.pojo.entity.Role;
import com.bosssoft.ct.springcloud.pojo.entity.User;
import lombok.*;
import org.springframework.beans.BeanUtils;

import java.util.HashSet;
import java.util.Set;

/**
 * @author ChenTong
 * @version 1.0
 * @description userVO
 * @date 2020/6/21 15:24
 * @modified
 **/
public class UserVO extends BaseVO{
    private String username;
    private String mobile;
    private String email;
    private Boolean state;
    private Set<String> rolesName;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getState() {
        return state;
    }

    public void setState(Boolean state) {
        this.state = state;
    }

    public Set<String> getRolesName() {
        return rolesName;
    }

    public void setRolesName(Set<String> rolesName) {
        this.rolesName = rolesName;
    }

    public void entityToVO(User user){
        // 转换
        BeanUtils.copyProperties(user,this);
        // 转换role
        Set<Role> roles = user.getRoles();
        this.rolesName = new HashSet<>();
        roles.iterator().forEachRemaining(role->
            this.rolesName.add(role.getRoleName())
        );
    }
}
